#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <unistd.h>
#include <stdlib.h>
#define PATHNAME "/root/xywl/test/test.c"

#define PROJ_ID 0x666
#define SIZE 4096

int main() {
    key_t key = ftok(PATHNAME, PROJ_ID);
    if(key < 0) {
        perror("ftok error");
        exit(1);
    }
    int shm = shmget(key, SIZE, IPC_CREAT | IPC_EXCL);
    if(shm < 0) {
        perror("shmget error");
        exit(2);
    }
    printf("key: %x\n", key);
    printf("shm: %d\n", shm);
    sleep(5);
    shmctl(shm, IPC_RMID, NULL);
    sleep(5);
    return 0;
}
